package com.leetcode;

/**
 * 167. 两数之和 II - 输入有序数组
 * 双指针查找
 */
public class Solution167_2 {

    public int[] twoSum(int[] numbers, int target) {
        int n = numbers.length;
        int head = 0;
        int tail = n - 1;
        while (head <= tail) {
            int num = numbers[head] + numbers[tail];
            if (num == target) {
                return new int[]{head + 1, tail + 1};
            } else if (num < target) {
                head++;
            } else {
                tail--;
            }
        }
        return new int[]{-1, -1};
    }

}
